import React, { Component } from 'react';
import RouterView from './router'
import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom'
import Storage from '@/utils/storage'

@connect(state => ({
  footerMenu: state.getIn(['ck', 'footerMenu'])
}), null)
@withRouter
class App extends Component {

  constructor(props) {
    super(props);
    this.accessUri = ['/fav', '/click']
  }

  checkLogin(pathname) {
    const bool = this.accessUri.some(item => {
      return new RegExp(item).test(pathname)
    })
    if (bool && !Storage.get('islogin')) {
      this.props.history.push('/login')
      return;
    }
  }

  componentDidMount() {
    // console.log(this.accessUri.includes(this.props.location.pathname));
    this.checkLogin(this.props.location.pathname)

    // 必须路由有改变时才触发，而且第1次还不执行
    this.props.history.listen(location => {
      this.checkLogin(location.pathname)
    })
  }


  render() {
    return (
      <>
        {/* <h3 style={{ display: this.props.footerMenu }}>aaa</h3> */}
        <RouterView />
      </>
    );
  }
}

export default App;
